package com.gest.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.swing.JOptionPane;

public class KacemUtil {
	public static boolean IsMacCorrect(String AdrsMAC) {
		boolean IsMacCorrect = false;
		String macStr = "";
		InetAddress ip;
		try {
			ip = InetAddress.getLocalHost();
			System.out.println("Current IP address : " + ip.getHostAddress());
			NetworkInterface network = NetworkInterface.getByInetAddress(ip);
			byte[] mac = network.getHardwareAddress();
			System.out.print("Current MAC address : ");
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < mac.length; i++) {
				sb.append(String.format("%02X%s", mac[i],
						(i < mac.length - 1) ? "-" : ""));
			}
			System.out.println(sb.toString());
			macStr = sb.toString();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (SocketException e) {
			e.printStackTrace();
		}

		if (macStr.equals(AdrsMAC)) {
			IsMacCorrect = true;
		}
		return IsMacCorrect;
	}

	public static void aff(String string) {
		JOptionPane.showMessageDialog(null, string, "Info",
				JOptionPane.INFORMATION_MESSAGE);
	}

	public static boolean isInteger(String input) {
		try {
			Integer.parseInt(input);
			return true;
		} catch (Exception exception) {
			return false;
		}
	}

	public static boolean isFloat(String input) {
		try {
			Float.parseFloat(input);
			return true;
		} catch (Exception exception) {
			return false;
		}
	}

	public static String SeparateurDeMilliers(float f) {
		double d = f;
		NumberFormat formatter = null;
		formatter = java.text.NumberFormat.getInstance(java.util.Locale.FRENCH);
		String s = "";
		formatter = new DecimalFormat("##,##0.00 DA");
		s = formatter.format(d);
		return s;
	}

}
